package com.chenjiajin.jackson_test.controller;

import com.chenjiajin.domain.Department;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author chenjiajin
 * @date 2023/4/14
 */
@RestController
public class DemoController {


    @PostMapping("demo")
    public String demo(HttpServletRequest request) throws IOException {
        Department demo = new ObjectMapper().readValue(request.getInputStream(), Department.class);
        System.err.println("demo = " + demo);

        // readValue方法参数可以是输入流 , 一般框架内部使用得比较多
        // 解析POST请求的请求体json数据为对象 , demo = Department(id=1, name=开发部, sn=DEV)

        return "success";
    }

}
